<?php
/**
 * 搜索列表页
 * Class Index
 */
class SearchController extends Controller{

	private $M_tags;
	private $M_taghasnews;
	private $M_news;
    /**
     * 构造方法
     * 初始化
     */
    public function __construct(){
        $this->M_tags = Model::getInstance('tags');
		$this->M_taghasnews = Model::getInstance('tag has news');
		$this->M_news = Model::getInstance('news');
    }
	
    //搜索显示
    public function index(){
		$q = $this->input->get('q',null);
		
		$list = array();
		
		if(!empty($q)){
			$search_tags = explode(' ', $q);
			
			$tags = $this->M_tags->mulitGetTagInfoByNames($search_tags);
			
			$tag_ids = array();
			foreach((array)$tags as $k=>$v){
				$tag_ids[] = $v['tag_id'];
			}
			
			$new_ids = $this->M_taghasnews->mulitGetNewIdByTagIds($tag_ids);
			
			$if(!empty($new_ids)){
				$page = (int)$this->input()->get('page',1);
				$filter = array('new_ids'=>$new_ids);
				//首页新闻列表
				$list = $this->M_news->getNewListByCategoryId($page,15,$filter);
			}
		}
		
		$data = array(
            'list'=>$list
        );
		
		Template::show('search/index.php', $data);
	}
}

?>